package com.capacitydorm.server.common.util;

import com.capacitydorm.server.common.vo.StudentVo;
import com.capacitydorm.server.dao.DormMapper;
import com.capacitydorm.server.dao.FloorMapper;
import com.capacitydorm.server.dao.TowerMapper;
import com.capacitydorm.server.dao.WxuserMapper;
import com.capacitydorm.server.domain.*;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class StudentsUtils {

    @Autowired
    private  DormMapper   dormMapper;
    @Autowired
    private  FloorMapper  floorMapper;
    @Autowired
    private   TowerMapper  towerMapper;
    @Autowired
    private  WxuserMapper  wxuserMapper;


    public  StudentVo  findByOther(Student  student){
        StudentVo  studentVo=new StudentVo();
        System.out.println("Utils:"+student.getWxuserId());
        wxuser wxu = wxuserMapper.findById(student.getWxuserId()+"");
        Dorm dorm = dormMapper.findById(student.getDormId());
        Floor floor = floorMapper.findById(dorm.getFloorId());
        Tower tower = towerMapper.selectByPrimaryKey(floor.getTowerId());
        BeanUtils.copyProperties(student,studentVo);
        studentVo.setDorm(dorm);
        studentVo.setWxuser(wxu);
        studentVo.setFloor(floor);
        studentVo.setTower(tower);
        return   studentVo;
    }
}
